package com.act.web;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.act.domain.Sumday;
import com.act.dto.PagerDTO;
import com.act.dto.Response;
import com.act.service.api.ISumdayService;
import com.act.util.LoggerUtil;
import com.act.vo.PagerVo;

/**
* @Desccription:类说明
* @Author: 刘承军
* @E-mail:923050345@qq.com
* @Date:2017年11月6日 下午5:13:24  
*/

@RestController
@RequestMapping("/sumday")
public class SumdayController {
	
	@Resource
	private ISumdayService sumdayService;	
	
	private final Logger LOGGER = Logger.getLogger(SumdayController.class);	
	
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Response add(Sumday sumday) {
    	 try {
    		 sumdayService.add(sumday);
             return Response.success();
         } catch (Exception e) {
        	 LoggerUtil.error(LOGGER, e);
             return Response.fail();
         }
    }
    
    @RequestMapping(value = "/update",method = RequestMethod.POST,consumes = "application/json")
    @ResponseBody
    public Response update(@RequestBody List<Sumday> dayclears) {
    	 try {
    		 for (Sumday sumday : dayclears) {
    			 sumdayService.update(sumday);
    		 }
             return Response.success();
         } catch (Exception e) {
        	 LoggerUtil.error(LOGGER, e);
         }
    	 return Response.fail();
    }
    
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Response delete(@PathVariable int id) {
    	 try {
    		 sumdayService.delete(id);
             return Response.success();
         } catch (Exception e) {
        	 LoggerUtil.error(LOGGER, e);
         }
    	 return Response.fail();
    }

    @RequestMapping(value = "/getNow",method = RequestMethod.POST)
    @ResponseBody
    public Response getNow(@RequestBody PagerDTO pagerDTO) {
            try {
            	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        		String date = simpleDateFormat.format(new Date());
            	PagerVo<Map> lists=  sumdayService.getNow(date,pagerDTO);
                return Response.success(lists);
            }catch (Exception e) {
                LoggerUtil.error(LOGGER, e);
            }
            return Response.fail();   
    }    
    
    @RequestMapping(value = "/getByJobnumTime/{jobnum}/{startTime}/{endTime}",method = RequestMethod.POST)
    @ResponseBody
    public Response getByJobnum(@PathVariable String jobnum,@PathVariable String startTime,@PathVariable String endTime,@RequestBody PagerDTO pagerDTO) {
            try {
            	PagerVo<Map> lists=  sumdayService.getByJobnum(jobnum, startTime, endTime, pagerDTO);
                return Response.success(lists);
            }catch (Exception e) {
                LoggerUtil.error(LOGGER, e);
            }
            return Response.fail();   
    }     

    @RequestMapping(value = "/getById/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Response getById(@PathVariable int id) {
            try {
            	Sumday s=  sumdayService.getById(id);
                return Response.success(s);
            }catch (Exception e) {
                LoggerUtil.error(LOGGER, e);
            }
            return Response.fail();   
    }  
    
    @RequestMapping(value = "/getByIdInweek/{jobnum}",method = RequestMethod.GET)
    @ResponseBody
    public Response getByIdInweek(@PathVariable String jobnum) {
            try {
            	List<Sumday> lists =  sumdayService.getByIdInweek(jobnum);
                return Response.success(lists);
            }catch (Exception e) {
                LoggerUtil.error(LOGGER, e);
            }
            return Response.fail();   
    } 
}
